package org.wdhl.xzc.wdhlxzctool.mixin;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;
import java.util.function.Supplier;

@Mixin(xyz.pixelatedw.mineminenomi.entities.mobs.OPEntity.class)
public class OPEntityMixin {
    @Inject(method = "getRandomSword(Ljava/util/List;)Lnet/minecraft/item/ItemStack;",
            at = @At("HEAD"), cancellable = true, remap = false)
    private void onGetRandomSword(List<Supplier<? extends Item>> list, CallbackInfoReturnable<ItemStack> cir) {
        // 检查列表是否为null，如果是则取消原始方法并返回默认的铁剑
        if (list == null) {
            cir.setReturnValue(new ItemStack(Items.IRON_SWORD));
            cir.cancel();
            // 控制台打印提示 问题已修复
            System.out.println("问题：[OPEntityMixin] 剑 列表为 null，已修复！");
        }
    }
}